package com.tongji.seller.utils
{
	import mx.collections.ArrayCollection;

	public class SelectTools
	{
		/**
		 *  完成全选功能
		 * @param oldArray 已选择过的
		 * @param newArray 将要加入选择的
		 * @return ArrayCollection
		 * 
		 */		
		public static  function selectAll(oldArray:ArrayCollection, newArray:ArrayCollection):ArrayCollection
		{
			for (var i:int = 0; i < newArray.length; i++)
			{
				if (!oldArray.contains(newArray[i]))
				{
					oldArray.addItem(newArray[i]);
				}
			}
			for (var m:int = 0; m < oldArray.length; m++)
			{
				for (var n:int = m + 1; n < oldArray.length; n++)
				{
					if (oldArray.getItemAt(m).ImgUrl == oldArray.getItemAt(n).ImgUrl)
					{
						oldArray.removeItemAt(n);
						n--;
					}
				}
			}
			
			return oldArray;
		}
		
		/**
		 *  完成反选功能
		 * @param oldArray 已选择过的
		 * @param newArray 当前的总数据
		 * @return ArrayCollection
		 * 
		 */	
		public static function selectOther(oldArray:ArrayCollection, newArray:ArrayCollection):ArrayCollection
		{
			var k:int = oldArray.length;
			var tempArray:ArrayCollection = new ArrayCollection();
			for (var m:int = 0; m < newArray.length; m++)
			{
				tempArray.addItem(newArray[m]);
			}
			for (var i:int = 0; i < tempArray.length; i++)
			{
				for (var j:int = 0; j < k; j++)
				{
					if (tempArray[i].ImgUrl == oldArray[j].ImgUrl)
					{
						oldArray.removeItemAt(j);
						j--;
						tempArray.removeItemAt(i);
						i--;
						k--;
						break;
					}
				}
			}
			for (var n:int = 0; n < tempArray.length; n++)
			{
				oldArray.addItem(tempArray[n]);
			}
			return oldArray;
		}
	}
}